using System;
using System.Collections.Generic;
using UnityEngine;

public class ConnectionSpeedIndicatorConfig : ScriptableObject
{
	[Serializable]
	public class ConnectionSpeedRange
	{
		public string name;

		public Color colour;

		[Range(1f, 5f)]
		public int numberOfShadedBars;

		public FloatRange pingRange;

		public bool isIncluding(float connectionPing, float framerateDifference)
		{
			int num = 1;
			FloatRange floatRange = default(FloatRange);
			floatRange.min = GetGameTimescale(pingRange.max, num);
			floatRange.max = GetGameTimescale(pingRange.min, num);
			FloatRange floatRange2 = floatRange;
			int num2 = 1;
			floatRange = default(FloatRange);
			floatRange.min = (float)(2 * num2) - floatRange2.max;
			floatRange.max = (float)(2 * num2) - floatRange2.min;
			FloatRange floatRange3 = floatRange;
			float gameTimescale = GetGameTimescale(connectionPing, framerateDifference);
			return floatRange2.isIncluding(gameTimescale) || floatRange3.isIncluding(gameTimescale);
		}

		public float GetGameTimescale(float ping, float framerateDifference)
		{
			return 1f * framerateDifference / (1f + ping * 0.001f);
		}
	}

	private static ConnectionSpeedIndicatorConfig instance_;

	public List<ConnectionSpeedRange> speedRanges = new List<ConnectionSpeedRange>();

	public static ConnectionSpeedIndicatorConfig instance
	{
		get
		{
			if (instance_ == null)
			{
				instance_ = Resources.Load("ConnectionSpeedIndicatorConfig", typeof(ConnectionSpeedIndicatorConfig)) as ConnectionSpeedIndicatorConfig;
			}
			return instance_;
		}
	}

	public ConnectionSpeedRange GetRangeForPing(float ping)
	{
		foreach (ConnectionSpeedRange speedRange in speedRanges)
		{
			if (speedRange.pingRange.isIncluding(ping))
			{
				return speedRange;
			}
		}
		if (speedRanges.Count > 0)
		{
			return speedRanges[0];
		}
		return null;
	}

	public ConnectionSpeedRange GetRangeForScale(float connectionPing, float framerateDifference)
	{
		foreach (ConnectionSpeedRange speedRange in speedRanges)
		{
			if (speedRange.isIncluding(connectionPing, framerateDifference))
			{
				return speedRange;
			}
		}
		if (speedRanges.Count > 0)
		{
			return speedRanges[0];
		}
		return null;
	}
}
